package code09集合.List;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 黄衡熙
 * @version 1.0
 */
public class Test04_与数组的转换 {

    public static void main(String[] args) {
        toArray();
        toList();
    }

    public static void toArray() {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(3);
        list.add(4);
        list.add(6);
        list.add(7);
        list.add(8);
        Object[] arr = list.toArray();
        System.out.println(Arrays.toString(arr));
        System.out.println("------------------------");
    }

    public static void toList() {
        // 对于数组
        String[] arr = {"admin", "jack", "tom", "lucy"};
        List<String> list = Arrays.asList(arr);
        System.out.println(list);

        // 对于可变长参数
        List<Integer> list2 = Arrays.asList(1, 2, 3, 5, 6, 7);
        System.out.println(list2);
    }
}